package com.cy.store.controller;

import com.cy.store.entity.Order;
import com.cy.store.service.IOrderService;
import com.cy.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author: AngJie
 * @create: 2022-02-11 13:56
 **/
@RequestMapping("orders")
@RestController
public class OrderController extends BaseController {

    @Autowired
    IOrderService orderService;

    @RequestMapping("create")
    public JsonResult<Order> create(Integer aid, @RequestParam("cids") List<Integer> cids, HttpSession session) {
        Integer uid = getUidFromSession(session);
        String username = getUsernameFromSession(session);
        Order data = orderService.create(aid, uid, username, cids);
        return new JsonResult<>(OK, data);
    }
}
